package com.wind.plugin.config;

import cn.hutool.core.lang.Singleton;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

@State(name = "CustomerIdSettings",
        storages = @Storage("customerIdSettings.xml"))
public class CustomerIdSettings implements PersistentStateComponent<CustomerIdSettings> {

    private List<String> customerIdKeywords;

    public CustomerIdSettings() {
        // 初始化默认的客户号关键词
        customerIdKeywords = new ArrayList<>();
        customerIdKeywords.add("imCustNo");
    }

    public List<String> getCustomerIdKeywords() {
        return customerIdKeywords;
    }

    public void setCustomerIdKeywords(List<String> customerIdKeywords) {
        this.customerIdKeywords = customerIdKeywords;
    }

    public void addCustomerIdKeyword(String keyword) {
        if (keyword != null && !keyword.trim().isEmpty() && !customerIdKeywords.contains(keyword)) {
            customerIdKeywords.add(keyword);
        }
    }

    public void removeCustomerIdKeyword(String keyword) {
        customerIdKeywords.remove(keyword);
    }

    public static CustomerIdSettings getInstance() {
        return Singleton.get(CustomerIdSettings.class);
    }

    @Override
    public @NotNull CustomerIdSettings getState() {
        return this;
    }

    @Override
    public void loadState(@NotNull CustomerIdSettings state) {
        this.customerIdKeywords = state.customerIdKeywords != null ? state.customerIdKeywords : new ArrayList<>();
    }
}
